package com.chanyachting.emall.action.club;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.domain.Newsactivity;
import com.chanyachting.emall.form.CompanyForm;
import com.chanyachting.emall.service.CompanyService;
import com.chanyachting.emall.service.NewsActivityService;
import com.chanyachting.emall.serviceImpl.CompanyServiceImpl;
import com.chanyachting.emall.serviceImpl.NewsActivityServiceImpl;

public class ReadCompanyOfOneNewsAction  extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		CompanyService comService = new CompanyServiceImpl();
		NewsActivityService newsService = new NewsActivityServiceImpl();

		System.out.println("=========tmpNews=================");
		CompanyForm tForm = (CompanyForm)form;
		if(tForm.getId() == null) {
			return mapping.findForward("error");
		}
		
		List<Company> alList = null;
		
		alList = comService.getCompanyById(tForm.getId().toString());
		if (alList.size() == 0) {
			return mapping.findForward("error");
		}
		
		System.out.println("tmpNews=================" + tForm.getNewsId());
		List<Newsactivity> tmpList = newsService.getNewsActivityByNewsid(tForm.getNewsId());
		
		if(tmpList == null || tmpList.size() == 0) {
			return mapping.findForward("error");
		}
		
		System.out.println("tmpNews=================" + tmpList.get(0).getId());
		tForm.setNews(tmpList.get(0));
		tForm.setComp(alList.get(0));
		return mapping.findForward("readClubCompanyOneNews");
	}
}
